<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* 车辆结构信息管理
*/
class Car_structure extends MY_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('Car_structure_model');
	}
	//查询车辆结构列表
	public function index()
	{
	
		$structurename = $this->input->get_post('structurename');
		$start =  intval($this->input->get_post('per_page'));

		$params = array(
			'structurename' =>$structurename 
			,'start' => $start
			,'length'=>$this->page_size);

		$result = $this->Car_structure_model->select_page($params);
		$result['params'] = $params;

		//分页设置
		$base_url =  site_url("c=car_structure&m=index&structurename=$structurename");
		$result['pagelink'] = $this->create_page_links($base_url,$result['count']);

		$this->show_view('carStructureList',$result);
		
	}

	//编辑车辆结构
	public function edit()
	{

		$this->form_validation->set_rules('structurename', '车辆结构', 'required');

		$structureid = $this->input->get_post('structureid');

		$structureeditsubmit = $this->input->post('structureeditsubmit');
		$resultinfo = $this->Car_structure_model->select_by_id($structureid);
		$resultinfo['method'] ='edit';
		if($structureeditsubmit  && $this->form_validation->run())
		{
			$structurename = $this->input->get_post('structurename');
			$result = $this->Car_structure_model->update($structureid,array('structurename'=>$structurename));
			$this->show_message("编辑车辆结构信息成功",site_url("c=car_structure&m=index"));
			
		}
		else
		{		
			$this->show_view('carStructureEdit',$resultinfo);
		}
	}
	//新增车辆结构
	public function add()
	{
		$this->form_validation->set_rules('structurename', '车辆结构', 'required');
		
		$structureeditsubmit = $this->input->post('structureeditsubmit');
		$resultinfo  =array('method'=>'add');
		if($structureeditsubmit  && $this->form_validation->run())
		{
			
			$structurename = $this->input->get_post('structurename');
 
			$result = $this->Car_structure_model->insert(array('structurename'=>$structurename));

			$this->show_message("新增车辆结构信息成功",site_url("c=car_structure&m=index"));
			
		}
		else
		{		
			
			$this->show_view('carStructureEdit',$resultinfo);
			
		}
	}
	//删除车辆结构
	public function delete()
	{
		$structureid = $this->input->get_post('structureid');
		$result = $this->Car_structure_model->delete($structureid);
		

		if($result['success'])
		{
			$this->show_message("删除车辆结构信息成功",site_url("c=car_structure&m=index"));
		}
		else
		{
			$this->show_message($result['message'],site_url("c=car_structure&m=index"));
		}
	}

 
}